package com.zoe.onelink.core.web.jackson.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.zoe.onelink.common.enumeration.BaseEnum;

import java.io.IOException;
import java.io.Serializable;

/**
 * <p>标题: 返回枚举JSON字符串</p>
 * <p>描述: 在实体来的字段上使用 @JsonSerialize(using = JackEnumForJsonSerializer.class) 指定</p>
 * <p>版权: Copyright (c) 2021</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2021-06-21
 */
public class JacksonEnumForJsonSerializer extends JsonSerializer<BaseEnum<Serializable>> {
    @Override
    public void serialize(BaseEnum<Serializable> value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        gen.writeStartObject();
        gen.writeObjectField("code", value.getCode());
        gen.writeObjectField("desc", value.getDesc());
        gen.writeEndObject();
    }
}
